﻿using System;
using CoreRay;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CoreRay.Testing
{
    /// <summary>
    /// This is a test class for VertexFormatTest and is intended
    /// to contain all VertexFormatTest Unit Tests
    /// </summary>
    [TestClass]
    public class VertexFormatTest
    {
        /// <summary>
        /// A test for vertex size.
        /// </summary>
        [TestMethod]
        public void VertexSizeTest()
        {
            VertexFormat target = new VertexFormat();
            target.AddElement("Position", typeof(Vector3));
            target.AddElement("Normal", typeof(Vector3));

            int expected = 24;
            int actual = target.VertexSize;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        /// A test for indexer.
        /// </summary>
        [TestMethod]
        public void IndexerTest()
        {
            VertexFormat target = new VertexFormat();
            target.AddElement("Position", typeof(Vector3));

            VertexFormatElement actual = target["Position"];

            Assert.IsTrue(actual.Name == "Position");
        }

        /// <summary>
        /// A test for indexer.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void IndexerWithWrongElementTest()
        {
            VertexFormat target = new VertexFormat();
            target.AddElement("Position", typeof(Vector3));

            VertexFormatElement actual = target["Position2"];
        }

        /// <summary>
        /// Add element test.
        /// </summary>
        [TestMethod]
        public void AddElementTest()
        {
            VertexFormat target = new VertexFormat();

            target.AddElement("Position", typeof(Vector3));

            Assert.IsTrue(target.Contains("Position"));
        }

        /// <summary>
        /// Add same elements test.
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddSameElementsTest()
        {
            VertexFormat target = new VertexFormat();

            target.AddElement("Position", typeof(Vector3));
            target.AddElement("Position", typeof(Vector3));
        }

   

        /// <summary>
        /// Contains test.
        /// </summary>
        [TestMethod]
        public void ContainsTest()
        {
            VertexFormat target = new VertexFormat();

            target.AddElement("Position", typeof(Vector3));
            target.AddElement("Normal", typeof(Vector3));

            Assert.IsTrue(target.Contains("Position"));
        }

        /// <summary>
        /// Contains test.
        /// </summary>
        [TestMethod]
        public void Contains2Test()
        {
            VertexFormat target = new VertexFormat();

            target.AddElement("Position", typeof(Vector3));
            target.AddElement("Normal", typeof(Vector3));

            Assert.IsFalse(target.Contains("Position2"));
        }

        /// <summary>
        /// Enumerator test.
        /// </summary>
        [TestMethod]
        public void EnumeratorTest()
        {
            VertexFormat target = new VertexFormat();

            target.AddElement("Position", typeof(Vector3));
            target.AddElement("Normal", typeof(Vector3));

            int expected = 2;
            int actual = 0;

            foreach(VertexFormatElement element in target)
            {
                actual++;
            }

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        /// Equals test.
        /// </summary>
        [TestMethod]
        public void EqualsTest()
        {
            // Setup
            VertexFormat vertexFormat1 = new VertexFormat();
            vertexFormat1.AddElement("Position", typeof(Vector3));
            vertexFormat1.AddElement("Normal", typeof(Vector3));

            VertexFormat vertexFormat2 = new VertexFormat();
            vertexFormat2.AddElement("Position", typeof(Vector3));
            vertexFormat2.AddElement("Normal", typeof(Vector3));

            // Execute
            bool expected = true;
            bool actual = vertexFormat1.Equals(vertexFormat2);

            // Verify
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        /// Unequals test.
        /// </summary>
        [TestMethod]
        public void UnequalsTest()
        {
            // Setup
            VertexFormat vertexFormat1 = new VertexFormat();
            vertexFormat1.AddElement("Position", typeof(Vector3));
            vertexFormat1.AddElement("Normal", typeof(Vector3));

            VertexFormat vertexFormat2 = new VertexFormat();
            vertexFormat2.AddElement("Position2", typeof(Vector3));
            vertexFormat2.AddElement("Normal", typeof(float));

            // Execute
            bool expected = false;
            bool actual = vertexFormat1.Equals(vertexFormat2);

            // Verify
            Assert.AreEqual(expected, actual);
        }
    }
}
